package ru.neoflex.dataobject;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class DataObjectDescriptorImpl implements DataObjectDescriptor {
	
	private final List<DataObjectProperty> properties;
	
	public DataObjectDescriptorImpl(List<DataObjectProperty> properties) {
		this.properties = properties;
	}

	@Override
	public List<DataObjectProperty> getProperties() {
		return properties;
	}

	@Override
	public boolean hasProperty(String property) {
		for (DataObjectProperty dataObjectProperty : properties) {
			if (dataObjectProperty.getName().equals(property)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public DataObjectProperty getProperty(String property) {
		for (DataObjectProperty dataObjectProperty : properties) {
			if (dataObjectProperty.getName().equals(property)) {
				return dataObjectProperty;
			}
		}
		return null;
	}

	@Override
	public Set<String> getPropertyNames() {
		Set<String> result = new HashSet<String>();
		for (DataObjectProperty dataObjectProperty : properties) {
			result.add(dataObjectProperty.getName());
		}
		return result;
	}
}
